<?php
/**
 * Created by PhpStorm.
 * User: zhengkunming
 * Date: 2018/12/26
 * Time: 3:17 PM
 */

ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set("Asia/Shanghai");

header('Content-Type:application/json; charset=utf-8');

$user = 'root';
$password = 'root123';
$db = 'lancaster_sun_campaign_h5_2019';
$host = 'localhost';
$port = 8889;
$socket = 'localhost:/Applications/MAMP/tmp/mysql/mysql.sock';
$link = mysqli_connect($host, $user, $password, $db, $port);

//if (!$link) {
//    echo "Error: Unable to connect to MySQL." . PHP_EOL;
//    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
//    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
//    exit;
//}
//
//
//echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
//echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
//
//mysqli_close($link);

$current_time = date("Y-m-d H:i:s");
$current_date = date("Y-m-d");


function rtJson($data = array())
{
    echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

//程序需要,写了一个获取当前星期的日期范围,也就是从星期一到星期日的日期范围。

function getWeekRange($date){

    $ret=array();

    $timestamp=strtotime($date);

    $w=strftime('%u',$timestamp);

    $ret['sdate']=date('Y-m-d 00:00:00',$timestamp-($w-1)*86400);

    $ret['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);

    return $ret;

}

//author:zhxia 获取指定日期所在月的开始日期与结束日期

function getMonthRange($date){

    $ret=array();

    $timestamp=strtotime($date);

    $mdays=date('t',$timestamp);

    $ret['sdate']=date('Y-m-1 00:00:00',$timestamp);

    $ret['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);

    return $ret;

}